package com.clgc.eduservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clgc.eduservice.entity.EduMajor;
import com.clgc.eduservice.service.EduMajorService;
import com.clgc.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 专业表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/eduservice/edu-major")
public class EduMajorController {

    @Autowired
    EduMajorService majorService;

    @ApiOperation("添加专业信息")
    @PostMapping("addMajor")
    public R addMajor(@RequestBody EduMajor major) {
        boolean flag = majorService.save(major);

        return flag ? R.ok() : R.error().message("添加专业信息失败");
    }

    @ApiOperation("删除专业信息")
    @DeleteMapping("deleteMajor/{id}")
    public R deleteMajor(@PathVariable String id) {
        boolean flag = majorService.removeById(id);
        return flag ? R.ok() : R.error().message("删除专业失败");
    }

    @ApiOperation("修改专业信息")
    @PostMapping("updateMajor")
    public R updateMajor(@RequestBody EduMajor major) {
        boolean flag = majorService.updateById(major);
        return flag ? R.ok() : R.error().message("修改专业失败");
    }

    @ApiOperation("查询专业信息")
    @GetMapping("getMajorInfo/{page}/{size}")
    public R getMajorInfo(@PathVariable long page, @PathVariable long size) {

        Page<EduMajor> majorPage = new Page(page, size);

        majorService.page(majorPage, null);

        return R.ok().data("page", majorPage);
    }

}

